// 时间戳转换成刚刚、几分钟前、几小时前、几天前

//刚刚
var just = new Date().getTime();

//几分钟前
var afewminutesago = new Date("Nov 29, 2016 00:50:00").getTime();

//几周前
var afewweekago = new Date("Nov 29, 2016 00:50:00").getTime();

//几年前
var someday = new Date("Nov 21, 2012 01:15:00").getTime();

var helloData = {
    time: afewweekago
}

function getDateDiff(dateTimeStamp) {
    var result;
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
  
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = now - dateTimeStamp;
    if (diffValue < 0) {
        return;
    }
    var monthC = diffValue / month;
    var weekC = diffValue / (7 * day);
    var dayC = diffValue / day;
   // console.log(dayC)
    var hourC = diffValue / hour;
    var minC = diffValue / minute;
    if (weekC >= 1) {
        result = "" +"一周前";
    } else if (dayC >= 1) {
        var arr=['一','二','三']
        if (parseInt(dayC)>=3){
            result = arr[2] + "天前";
        }else{
            result = arr[parseInt(dayC)-1] + "天前";
        }
       
    } else {
        var start = new Date(new Date().toLocaleDateString()).getTime();//当前时间戳
        if (dateTimeStamp < start){
            result= '一天前'
        }else{
            // console.log(start)
            //type 表示从哪个页面取调用的
            var nowdata = new Date(); //当前时间
            var date = new Date(dateTimeStamp)
            var h = date.getHours();
            h = h < 10 ? ('0' + h) : h;
            var minute = date.getMinutes();
            minute = minute < 10 ? ('0' + minute) : minute;

            result = h + ':' + minute;
        }
      
    }
    return result;
};
module.exports = {
    indexTime: getDateDiff
}